﻿@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>layout 后台大布局 - Layui</title>
    <link href="~/lib/layui/css/layui.css" rel="stylesheet" />
    <script src="~/lib/layui/layui.js"></script>
    <script src="~/lib/jquery/jquery-1.12.4.js"></script>
    <script src="~/lib/ckeditor/ckeditor.js"></script>
    <script src="~/lib/localforage/localforage.min.js"></script>
    <script src="~/lib/ckeditor/config.js" asp-append-version="true"></script>
</head>
<body class="layui-layout-body">
    <div class="layui-layout-admin">
        <div class="layui-header layui-bg-cyan">
            <div class="layui-logo" style="    padding-left: 50px;    text-align: left;    width: 100%;">
                <span style="color: #D2D3D4; font-size: 24px">后台管理</span>
            </div>
            <ul class="layui-nav layui-layout-right">
                <li class="layui-nav-item">@Html.ActionLink("退出", "Logout", "Account")</li>
            </ul>
            @*<!-- 头部区域（可配合layui已有的水平导航） -->
                <ul class="layui-nav layui-layout-left">
                    <li class="layui-nav-item">
                        <a href="">控制台</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="">商品管理</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="">用户</a>
                    </li>
                    <li class="layui-nav-item">
                        <a href="javascript:;">其它系统</a>
                        <dl class="layui-nav-child">
                            <dd>
                                <a href="">邮件管理</a>
                            </dd>
                            <dd>
                                <a href="">消息管理</a>
                            </dd>
                            <dd>
                                <a href="">授权管理</a>
                            </dd>
                        </dl>
                    </li>
                </ul>
                <ul class="layui-nav layui-layout-right">
                    <li class="layui-nav-item">
                        <a href="javascript:;">
                            <img src="http://t.cn/RCzsdCq" class="layui-nav-img">
                            贤心
                        </a>
                        <dl class="layui-nav-child">
                            <dd>
                                <a href="">基本资料</a>
                            </dd>
                            <dd>
                                <a href="">安全设置</a>
                            </dd>
                        </dl>
                    </li>
                    <li class="layui-nav-item">@Html.ActionLink("退出", "Logout", "Account")</li>
                </ul>*@
        </div>
        <div class="layui-side layui-bg-cyan">
            <div class="layui-side-scroll">
                @{
                    //todo:以后做嵌套优化
                }
                <ul class="layui-nav layui-nav-tree layui-bg-cyan" lay-filter="test">
                    @{
                        var category = (List<CategoryViewModel>) ViewData["Category"];
                        foreach (var l0 in category.Where(s => s.ParentId == 0).OrderBy(s=>s.Sort))
                        {
                            @Html.Raw($"<li id=\"Category_{l0.Id}\" class=\"layui-nav-item\"><a href=\"{l0.Url}\">{Html.Encode(l0.Content)}</a>")
                            var l1S = category.Where(s => s.ParentId == l0.Id).OrderBy(s => s.Sort).ToList();
                            if (!l1S.Any())
                            {
                                @Html.Raw("</li>")
                                continue;
                            }
                            @Html.Raw("<dl class=\"layui-nav-child\">")
                            foreach (var l1 in l1S)
                            {
                                @Html.Raw($"<dd id=\"Category_{l1.Id}\" ><a href=\"{l1.Url}\">{Html.Encode(l1.Content)}</a></dd>")
                            }
                            @Html.Raw("</dl>")
                            @Html.Raw("</li>")
                        }
                    }
                </ul>
            </div>
        </div>
        @RenderBody()
        <div class="layui-footer">
            <!-- 底部固定区域 -->
            © layui.com - 底部固定区域
            <div class="layui-layout-right" style="margin-right: 20px">
                @Html.Raw(Html.Encode("耗时："))
                <span id="X-Response-Time-ms"></span>@Html.Raw(Html.Encode(" 毫秒"))
            </div>
        </div>
    </div>
    <script>
        $(function () {
            //JavaScript代码区域
            layui.use('element',
                function () {
                    var element = layui.element;
                    var xResponseTimeMs = $("#X-Response-Time-ms");
                    if (xResponseTimeMs.length === 1) {
                        xResponseTimeMs[0].innerText = getCookie("X-Response-Time-ms");
                    }
                });
            $('[id^=Category_]').each(function (i, data) {
                $(data).on("click", wsySetCategory);
            });
            $('[id^=Category_]').each(function (i, data) {
                window.localforage.getItem(data.id).then(function (val) {
                    if (val !== null) {
                        data.className = val; }
                    
                });
            });
        });
        function getCookie(cName) {
            if (document.cookie.length > 0) {
                var cStart = document.cookie.indexOf(cName + "="); //获取字符串的起点
                if (cStart !== -1) {
                    cStart = cStart + cName.length + 1; //获取值的起点
                    var cEnd = document.cookie.indexOf(";", cStart); //获取结尾处
                    if (cEnd === -1) cEnd = document.cookie.length; //如果是最后一个，结尾就是cookie字符串的结尾
                    return decodeURI(document.cookie.substring(cStart, cEnd)); //截取字符串返回
                }
            }
            return "";
        }
        function wsySetCategory(){
            $('[id^=Category_]').each(function (i, data) {
                window.localforage.setItem(data.id, data.className);
            });
        }

        $(function(){
          
        });
    </script>
</body>
</html>